package cn.xinfei.xdecision.engine.runner.executor.strategy.branch;

import cn.xinfei.xdecision.common.model.component.strategyout.StrategyOutput;
import cn.xinfei.xdecision.common.utils.enums.enginex.NodeTypeEnum;
import cn.xinfei.xdecision.common.vo.FieldInfoVo;
import cn.xinfei.xdecision.constant.EngineResultEnum;
import cn.xinfei.xdecision.engine.runner.context.XDecisionContext;
import cn.xinfei.xdecision.engine.runner.executor.NodeHandler;
import cn.xinfei.xdecision.engine.runner.executor.XRunner;
import cn.xinfei.xdecision.engine.runner.executor.model.StateTransmitModel;
import cn.xinfei.xdecision.engine.runner.executor.strategy.EngineNodeRunner;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;


/**
 * 结束节点
 */
@XRunner
@Slf4j
@Service
public class End extends EngineNodeRunner {

    @Override
    public String getServiceName() {
        return EngineNodeRunner.PRE + NodeTypeEnum.END.getType();
    }
    @Override
    public Map<String, StrategyOutput> getTerminalOutputFieldInfo(NodeHandler nodeHandler) {

        Map<String, StrategyOutput> fieldVos = new HashMap<>();

        return fieldVos;
    }

    public Map<String, FieldInfoVo> getInputFieldInfo(NodeHandler nodeHandler) {
        return null;
    }

    @Override
    public Map<String, StrategyOutput> getOutputFieldInfo(NodeHandler nodeHandler) {
        return null;
    }

    @Override
    public StateTransmitModel runNode(NodeHandler nodeHandler) {
        log.info("执行结束节点 runNode nodeCode:{}", nodeHandler.getEngineNode().getNodeCode());
        StateTransmitModel stateTransmitModel = XDecisionContext.getContext().getStateContext();
        stateTransmitModel.setNextNodeCode(null);
        return stateTransmitModel.setEngineResultEnum(EngineResultEnum.SUCCESS_END);
    }



    @Override
    public boolean terminalCondition(NodeHandler nodeHandler, Map<String, Object> nodeOutput, Map<String, Object> nodeInput) {
        return false;
    }
}
